/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.vinicius.hibernate;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Hibernate
 * Utility
 * class
 * with
 * a
 * convenient
 * method
 * to
 * get
 * Session
 * Factory
 * object.
 *
 * @author
 * viniciuspacheco
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
    
    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            Configuration cfg = new Configuration();
            cfg.configure("br/com/vinicius/hibernate/hibernate.cfg.xml");
            sessionFactory = cfg.buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Erro Iniciar a Sessão" + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
